

DEFINE VARIABLE part LIKE pt_part .

DEFINE VARIABLE um LIKE pt_um .

DEFINE VARIABLE ptdesc AS CHARACTER.

DEFINE STREAM bf.

DEFINE VARIABLE str AS CHARACTER.

INPUT FROM VALUE("f:\hk_src\audit\partdata.csv") .

OUTPUT STREAM bf TO VALUE("f:\hk_src\audit\pt_si_invt.txt").

REPEAT ON ERROR UNDO, RETRY :

    IMPORT DELIMITER "," part um ptdesc NO-ERROR .

    PUT STREAM bf "@@batchload xxpppsmt01.p" SKIP .

    FIND FIRST pt_mstr NO-LOCK WHERE pt_part = SUBSTRING(part, 1, LENGTH(part) - 1) 
        OR pt_part = SUBSTRING(part, 1, LENGTH(part) - 1) + "R" NO-ERROR.

    EXPORT STREAM bf part pt_site .

    FIND FIRST IN_mstr NO-LOCK WHERE IN_part = pt_part AND IN_site = pt_site NO-ERROR.

    str = """" + in_abc + """ - - - - """ + in_loc + """ - -" .

    PUT STREAM bf UNFORMATTED str  SKIP .

PUT STREAM bf "@@end" SKIP.

END.
